﻿using System;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using NNS.Enumeration;
using QLTB.BusinessObjects;

namespace QLTB.NguoiDung.UI
{
    public partial class frmThemNguoiDung : XtraForm
    {
        public frmThemNguoiDung()
        {
            InitializeComponent();
            Controls.Add(ucthem);
            ucthem.SaveSuccess += ucthem_Success;
        }

        public TBL_nhanvien Nhanvien
        {
            get { return ucthem.Nhanvien; }
            set
            {
                ucthem.Nhanvien = value;
                ucthem.InitBindings();
                ucthem.InitErrorProvider();
            }
        }

        public EditMode Mode
        {
            set
            {
                ucthem.EMode = value;
                if (value == EditMode.Add)
                {
                    Text = "Thêm người dùng";
                }
                else
                {
                    Text = "Thay đổi người dùng";
                }
            }
        }

        public event EventHandler Added;

        private void OnAdded(EventArgs e)
        {
            EventHandler _handler = Added;
            if (_handler != null) _handler(this, e);
        }


        private void ucthem_Success(object sender, object Item)
        {
            OnAdded(null);
        }

        private void frmThemNguoiDung_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = !Program._exit;
        }
    }
}